package com.finger.userservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.finger.modelservice.model.user.UserInfo;
import com.finger.modelservice.result.Result;
import com.finger.modelservice.vo.user.UserInfoQueryVo;
import com.finger.userservice.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 本接口用于后台管理员模块
 */
@RequestMapping("admin/user")
@RestController
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    // 用户信息条件查询带分页
    @PostMapping("{page}/{size}")
    public Result findPageUser(@PathVariable Integer page,
                               @PathVariable Integer size,
                               @RequestBody UserInfoQueryVo userInfoQueryVo){

        Page<UserInfo> userInfoPage = new Page<>(page, size);

        IPage<UserInfo> pageModel = userInfoService.pageUserInfo(userInfoPage, userInfoQueryVo);

        return Result.ok(pageModel);

    }

    @PutMapping("lock/{status}/{userId}")
    public Result lock(@PathVariable Integer status,
                       @PathVariable String userId){

        userInfoService.lock(status,userId);
        return Result.ok();
    }

    // 查看用户详情
    @GetMapping("show/{userId}")
    public Result showUserInfo(@PathVariable String userId){

        Map<String,Object> resultMap = userInfoService.showUserInfo(userId);

        return Result.ok(resultMap);
    }

    // 用户认证
    @PutMapping("approve/{userId}/{status}")
    public Result approve(@PathVariable String userId,
                          @PathVariable Integer status){

        userInfoService.approve(userId,status);

        return Result.ok();
    }
}
